package com.cwj.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cwj.common.domain.*;
import com.cwj.user.dao.DaoList;
import com.cwj.user.service.welcome;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class welcomeImpl implements welcome {
    @Resource
    private DaoList daoList;
    @Resource
    private ObjectMapper objectMapper;
    @Override
    public Map<String, Object> GetMessage(user user) throws JsonProcessingException {
       user= daoList.getUserDao().selectOne(new QueryWrapper<user>().allEq(objectMapper.readValue(objectMapper.writeValueAsString(user), new TypeReference<>() {})));

        Map<String,Object> MsgMap=new HashMap<>();
        MsgMap.put("film_folder_size",daoList.getFilmFolderDao().selectCount(new QueryWrapper<FilmFolder>().eq("uid", user.getUid())));

        MsgMap.put("watch_film_count",daoList.getWatchRecordDao().selectCount(new QueryWrapper<WatchRecord>().eq("uid", user.getUid())));

        MsgMap.put("down_film_count", daoList.getDownRecDao().selectCount(new QueryWrapper<DownloadRecord>().eq("uid", user.getUid())));

         MsgMap.put("up_film_count",daoList.getUpFilmDao().selectCount(new QueryWrapper<upFilm>().eq("uid", user.getUid())));

        MsgMap.put("last_watch_film",daoList.getWatchRecordDao().last_watch_film(user));
        //上传影片中最受欢迎
        MsgMap.put("film_folder_up_film_maximum", daoList.getWatchRecordDao().film_folder_up_film_maximum(user));

        return MsgMap;
    }
}
